package cn.itcast.bos.service.transit.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.transit.IInOutStorageInfoRepository;
import cn.itcast.bos.dao.transit.ITransitRepository;
import cn.itcast.bos.domain.transit.InOutStorageInfo;
import cn.itcast.bos.domain.transit.TransitInfo;
import cn.itcast.bos.service.transit.IInOutStorageInfo;

@Transactional
@Service
public class InOutStorageInfoImpl implements IInOutStorageInfo{
	@Autowired
	private IInOutStorageInfoRepository inOutStorageInfoRepository;
	
	@Autowired
	private ITransitRepository transitRepository;
	
	@Override
	public void save(InOutStorageInfo inOutStorageInfo, String transitInfoId) {
		inOutStorageInfoRepository.save(inOutStorageInfo);
		
		//查询TransitInfo
		TransitInfo transitInfo = transitRepository.findOne(Integer.parseInt(transitInfoId));
		
		//关联出入库信息到运输配送对象
		transitInfo.getInOutStorageInfos().add(inOutStorageInfo);
		
		//修改状态
		if (inOutStorageInfo.getOperation().equals("到达网点")) {
			transitInfo.setStatus("到达网点");
			//更新路径地址
			transitInfo.setOutletAddress(inOutStorageInfo.getAddress());
		}
	}

}
